<?php
class ReceitasController extends AppController {
	public $helpers = array('Html', 'Form');
	public function beforeFilter() {
		 $this->Auth->allow();
        //parent::beforeFilter();
       
    }
	public function index() {
	
		$this->set('receitas',$this->Receita->find('all'));		
	}
	
	function add() {
        if ($this->request->is('post')) {
            if ($this->Receita->save($this->request->data)) {
                $this->Session->setFlash('Your post has been saved.');
                $this->redirect(array('action' => 'index'));
            }
        }
		else {
			$this->loadModel('Malte');
			$this->set('models',$this->Malte->find('all'));
		}
    }
	
	function edit($id = null) 
	{
		if ($this->request->is('get')) {
			$this->request->data = $this->Receita->findById($id);
			//$this->redirect(array('action' => 'index'));
		} else {
			if ($this->Receita->save($this->request->data)) {
				$this->Session->setFlash('Your post has been updated.');
				$this->redirect(array('action' => 'index'));
			}
		}
	}
	
	function delete($id) {
	    if (!$this->request->is('get')) {
	        throw new MethodNotAllowedException();
	    }
	    if ($this->Receita->delete($id)) {
	        $this->Session->setFlash('The post with id: ' . $id . ' has been deleted.');
	        $this->redirect(array('action' => 'index'));
	    }
	}
}